/***************************Copyright-DO-NOT-REMOVE-THIS-LINE**
 *
 * Condor Software Copyright Notice
 * Copyright (C) 1990-2004, Condor Team, Computer Sciences Department,
 * University of Wisconsin-Madison, WI.
 *
 * This source code is covered by the Condor Public License, which can
 * be found in the accompanying LICENSE.TXT file, or online at
 * www.condorproject.org.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * AND THE UNIVERSITY OF WISCONSIN-MADISON "AS IS" AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, OF SATISFACTORY QUALITY, AND FITNESS
 * FOR A PARTICULAR PURPOSE OR USE ARE DISCLAIMED. THE COPYRIGHT
 * HOLDERS AND CONTRIBUTORS AND THE UNIVERSITY OF WISCONSIN-MADISON
 * MAKE NO MAKE NO REPRESENTATION THAT THE SOFTWARE, MODIFICATIONS,
 * ENHANCEMENTS OR DERIVATIVE WORKS THEREOF, WILL NOT INFRINGE ANY
 * PATENT, COPYRIGHT, TRADEMARK, TRADE SECRET OR OTHER PROPRIETARY
 * RIGHT.
 *
 ****************************Copyright-DO-NOT-REMOVE-THIS-LINE**/
#include <boost/current_function.hpp>

#include "MWFWorker.h"
#include "MWFTask.h"

/* init */
MWFWorker::MWFWorker() {
	MWprintf(50, "Enter: %s\n", BOOST_CURRENT_FUNCTION);

	workingTask = new MWFRenderFractalTask;

	MWprintf(50, "Left: %s\n", BOOST_CURRENT_FUNCTION);
}

/* destruct */
MWFWorker::~MWFWorker() {
	MWprintf(50, "Enter: %s\n", BOOST_CURRENT_FUNCTION);

	delete workingTask;

	MWprintf(50, "Left: %s\n", BOOST_CURRENT_FUNCTION);
}

/* Do benchmark and return result (usually the time to task t), t is supposed
 * to be a benchmark task.  In this app, it just send back a PI. */
double MWFWorker::benchmark(MWTask *t) {
	MWprintf(50, "Enter: %s\n", BOOST_CURRENT_FUNCTION);

	MWFRenderFractalTask *tl = dynamic_cast<MWFRenderFractalTask *> (t);
	tl->printself(30);

	MWprintf(50, "Left: %s\n", BOOST_CURRENT_FUNCTION);

	return 3.14159;
}

/* unpack the init data from the driver */
MWReturn MWFWorker::unpack_init_data(void) {
	MWprintf(50, "Enter: %s\n", BOOST_CURRENT_FUNCTION);
	MWprintf(50, "Left: %s\n", BOOST_CURRENT_FUNCTION);
	return OK;
}

/* Execute each task */
void MWFWorker::execute_task(MWTask *t) {
	MWprintf(50, "Enter: %s\n", BOOST_CURRENT_FUNCTION);
	int i;

#ifdef NO_DYN_CAST
	MWFRenderFractalTask *task = (MWFRenderFractalTask *) t;
#else
	MWFRenderFractalTask *task = dynamic_cast<MWFRenderFractalTask *> (t);
#endif

	task->printself(30);

	task->image = MandelbrotSet::render(task->options);

	MWprintf(50, "Left: %s\n", BOOST_CURRENT_FUNCTION);
}

MWTask* MWFWorker::gimme_a_task() {
	MWprintf(50, "Enter: %s\n", BOOST_CURRENT_FUNCTION);
	MWprintf(50, "Left: %s\n", BOOST_CURRENT_FUNCTION);

	return new MWFRenderFractalTask;
}

/* Just return a newly created application worker object */
MWWorker*
gimme_a_worker() {
	MWprintf(50, "Enter: %s\n", BOOST_CURRENT_FUNCTION);
	MWprintf(50, "Left: %s\n", BOOST_CURRENT_FUNCTION);

	return new MWFWorker;
}
